﻿using CSUtils;
using G02;
using GlobalTripleJump;
using UnityEngine;

namespace TripleJump {
    /// <summary>
    /// 角色位置环
    /// </summary>
    public class CRolePosRing {
        public Transform root, distanceRing1, distanceRing2;
        Transform role;
        Vector3 originZoom1, originZoom2;

        public void Init(Transform role) {
            this.role = role;
            var gg = C128_AssetsCore.GetModel(GlobalTripleJumpCfg.artPath_rolePosiRing, 1);
            this.root = gg.transform;

            distanceRing1 = root.Find("distanceRing1").transform;
            distanceRing2 = root.Find("distanceRing2").transform;
            originZoom1 = distanceRing1.localScale;
            originZoom2 = distanceRing2.localScale;
            root.gameObject.SetActive(false);
        }

        bool isShow;

        public void IsShow(bool isShow) {
            this.isShow = isShow;
            root.gameObject.SetActive(isShow);
        }

        public void SetShow(Vector3 point, Vector3 normal, float distance) {
            if (isShow) {
                if (distance < 30) {
                    if (root.gameObject.activeSelf == false) {
                        root.gameObject.SetActive(true);
                    }
                } else {
                    if (root.gameObject.activeSelf) {
                        root.gameObject.SetActive(false);
                    }
                    return;
                }
            }
            //Debug.LogErrorFormat("_C_RolePosiRing______________________{0}____", distance);
            root.position = point + normal * 0.1f;
            root.rotation = Quaternion.FromToRotation(Vector3.forward, new Vector3(normal.x, -normal.z, normal.y));

            distanceRing1.localScale = (distance * 0.3f + 1) * originZoom1;

            distanceRing2.localScale = (distance * 1.5f + 1) * originZoom2;
        }
    }
}
